export interface IData {
	expire?: number
	// eslint-disable-next-line @typescript-eslint/no-explicit-any
	[key: string]: any
}
export default {
	set(key: string, data: IData) {
		if (data.expire) {
			data.expire = new Date().getTime() + data.expire * 1000 //传进来的expire以秒为单位
		}
		localStorage.setItem(key, JSON.stringify(data))
	},
	get(key: string) {
		const data = localStorage.getItem(key)
		if (data) {
			const dataObj = JSON.parse(data)
			if (dataObj.expire && new Date().getTime() > dataObj.expire) {
				localStorage.removeItem(key)
				return null
			}
			return dataObj
		}
		return null
	},
}
